package com.sunfield.baseframe.http;

import android.app.Activity;

/**
 * Created by wangxl on 2016/11/29.
 */
public class HttpHeader {
    private static HttpHeader instance = new HttpHeader();

    private HttpHeader() {
    }

    public static HttpHeader getInstance() {
        if(instance.mHttpHeadProvider == null){
            throw new RuntimeException("You must set HttpHeadProvider before you call a http request");
        }
        return instance;
    }

    HttpHeadProvider mHttpHeadProvider;

    public static void setHttpHeadProvider(HttpHeadProvider httpHeadProvider) {
        instance.mHttpHeadProvider = httpHeadProvider;
    }

    public interface HttpHeadProvider {
        String getHttpBaseUrl();

        String getUserId();

        String getUserSSID();

        Class<? extends Activity> getLoginClass();
    }

    public String getHttpBaseUrl() {
        return mHttpHeadProvider == null ? "" : mHttpHeadProvider.getHttpBaseUrl();
    }

    public String getUserId() {
        return mHttpHeadProvider == null ? "" : mHttpHeadProvider.getUserId();
    }

    public String getUserSSID() {
        return mHttpHeadProvider == null ? "" : mHttpHeadProvider.getUserSSID();
    }

    public Class<? extends Activity> getLoginClass() {
        return mHttpHeadProvider == null ? null : mHttpHeadProvider.getLoginClass();
    }
}
